package com.zc.emos.wx.task;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Scope;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import java.io.Serializable;

/**
 * @author 曾川
 * @version 1.0.0
 * @ClassName EmailTask.java
 * @Description
 *
 * 单例的会出现线程安全问题
 *
 * 多例的不会
 *
 *
 * @createTime 2022年01月10日 17:47:00
 */
@Component
@Scope("prototype")
public class EmailTask implements Serializable {

    @Autowired
    private JavaMailSender javaMailSender;

    @Value("${emos.email.system}")
    private String mailbox;

    @Async
    public void sendAsync(SimpleMailMessage message){
        message.setFrom(mailbox);
//        message.setCc(mailbox); //抄送给自己（发邮人）
        javaMailSender.send(message);
    }
}
